package com.oracle.application.controller;

import com.oracle.application.Fegin.vo.Member;
import com.oracle.application.config.JwtConfig;
import com.oracle.application.service.MemberService;
import com.oracle.application.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/")
public class MemberController {
    @Autowired
    private MemberService memberService;
    @Autowired
    private JwtConfig jwtConfig;

    @GetMapping("/login")
    public R login(String loginname,String loginpwd, HttpServletResponse response){
        R<Member> login = this.memberService.login(loginname, loginpwd);
        if (login.getCode()==200){
            String token = this.jwtConfig.createToken(loginname, loginpwd);
            response.setHeader("token",token);
            return new R(200,"success",null);
        }
        return new R(201,"fail",null);
    }
}
